//文件上传统一字段
function showfile() {
    $(".hidefile").show();
    $("#isUpload").val(1);
}
hidefile();
function hidefile() {
    $(".hidefile").hide();
    $("#isUpload").val(0);
};
var stepId = $CertusJsonAjax.getStepInstanceId();
var processId = $CertusJsonAjax.getProInstanceId();
$CertusFormAjax.ajax("findSeProList",{},function(response){
    var nhlTeams = [];
    var data = response.data;
    for (var i=0;i<data.length;i++){
        var arr={};
        arr.name=data[i].proName;
        arr.id = data[i].id;
        nhlTeams.push(arr);
    }
    //自动补全
    var nhl = $.map(nhlTeams, function (obj) {
        return {
            value: obj.name,
            data: { category: obj.id }
        };
    });
    // Initialize autocomplete with local lookup:
    $('#autocomplete1').devbridgeAutocomplete({
        lookup: nhl,
        minChars: 1,
        onSelect: function (suggestion) {
            $("#proId").val(suggestion.data.category);
        },
        showNoSuggestionNotice: true,
        noSuggestionNotice: 'Sorry, no matching results'
    });
    addProblem();
});

function changetp() {
    var proType =$("#proType").val();
    if (proType==null||proType==""){
        proType = $$scope.proType;
    }
    $CertusFormAjax.ajax("findProByType",{"proType":proType},function (response) {
        $$scope.prorlist = response.data;
    });
}

function getProMg(){
    var rproId =$("#rproId").val();
    if (rproId==null||rproId==""){
        rproId = $$scope.rproId;
    }
    $CertusFormAjax.ajax("findMg",{"proId":rproId},function (response) {
        $$scope.userName = response.data.userName;
        $$scope.userId = response.data.userId
    });
}

function addProblem() {
    $CertusFormAjax.ajax("findLcProblemList",{"processId":processId},function(response){
        var data = response.data;
        $$scope.proType = data.pro_type;
        $$scope.rproId = data.receive_pro_id+"";
        $$scope.rproName = data.rproName;
        $$scope.proId = data.pro_id+"";
        $$scope.proName = data.pro_name;
        changetp();
        getProMg();
        $$scope.prbLevel = data.prb_level+"";
        $$scope.companys = data.comp_id;
        $$scope.department = data.dept_id;
        $$scope.deliverDate = data.deliver_date;
        $$scope.prbDesc = data.prb_desc;
        $$scope.riskRating = data.risk_rating;
        $$scope.id = data.id;
    });

    //所属公司
    $CertusFormAjax.ajax("companyListByViewCode",{},function (response) {
        $$scope.comp = JSON.parse(response.data);
    });

    var fileId = "";
    $(".toRegu").on('click',function () {
        fileUpload($$scope,function (res){
            fileId = res.data;
        },null,$CertusFormAjax);
    })

    $(".submit").on('click',function () {
        var arr =$("form").serializeArray();
        var data = {};
        for (var i=0;i<arr.length;i++){
            data[arr[i].name] = arr[i].value;
        };
        data.stepId = stepId;
        data.fileUrl = fileId;
        $CertusFormAjax.ajax("editPrb",{"data":JSON.stringify(data)},function(response){
            layer.msg("提交成功");
            window.history.back();
        });
    });
}
function findDept() {
    getDept("");
}
function getDept(compId) {
    if (compId==""){
        compId = $("#companys").val();
    }
    $CertusFormAjax.ajax("deptList",{companyCode:compId},function (response) {
        $$scope.dept = JSON.parse(response.data);
    });
}